<?php
/**
 * Created by PhpStorm.
 * User: Guangpeng Chen
 * Date: 14-12-12
 * Time: 上午11:47
 */
define('ROOT_PATH','/var/www/html/new/');
include ROOT_PATH . '/com.inc.php';
include ROOT_PATH . '/d/class/SoapInit.class.php';
include ROOT_PATH . '/d/class/BillPay.php';

$memberID   = $_GET['mid'] ? intval($_GET['mid']) : 94;
$soap       = SoapInit::GetSoapInside();

$gets=array();
$str="select fid from uu_settle where aid=$memberID and status=0";
$GLOBALS['le']->query($str);
while($row=$GLOBALS['le']->fetch_assoc()){
    $gets[]=$row['fid'];
}
$bt = date('Y-m-d 00:00:00');
$et = date('Y-m-d H:i:s');
$output = array();
//print_r($gets);

$pays=array();
$str="select aid from uu_settle where fid=$memberID and status=0";
$GLOBALS['le']->query($str);
while($row=$GLOBALS['le']->fetch_assoc()){
    $pays[]=$row['aid'];
}

//foreach ($pays as $id) {
//    $b=new BillPay($memberID, $id,$soap,$GLOBALS['le'], 1);
//    $res = $b->ordersCount($bt, $et);
//    if ($res===0) continue;
//    $output[$id] =  $res;
//}
echo PHP_EOL . '应收款：' . PHP_EOL;
foreach($gets as $id){
    echo "分销商{$id}\n";
    $billOffline = new BillPay($id, $memberID,$soap,$GLOBALS['le'], BillPay::PAY_OFFLINE);
    $billOffline->getbill();
    $billOnline = new BillPay($id,$memberID,$soap,$GLOBALS['le'], BillPay::PAY_ONLINE);
    $billOnline->getbill();
}
echo PHP_EOL . '应付款：' . PHP_EOL;
foreach($pays as $id){
    echo "供应商{$id}\n";
    $billOffline = new BillPay($memberID,$id,$soap,$GLOBALS['le'], BillPay::PAY_OFFLINE);
    $billOffline->getbill();
    $billOnline = new BillPay($memberID,$id,$soap,$GLOBALS['le'], BillPay::PAY_ONLINE);
    $billOnline->getbill();
}

print_r($output);
